﻿using UnityEngine;
using System.Collections;

namespace AutoRoot
{
   public class DropdownMenuList : MonoBehaviour
   {
	  public GUIStyle titleStyle;
	  public GUIStyle itemStyle;
	  //public GUIStyle scrollbarBackground;
	  public GUIStyle scrollbarThumb;

	  // Use this for initialization
	  void Start () {
	  }

      void Update()
      {
         GetComponent<ScaleToFullScreen>().Start();
      }
	
		/*
		private string[] listItems = 
		{
			"Ch 1: Cold Winter",
			"Ch 2: Banana Farmer",
			"Ch 3: Madden XFL",
			"empty",
			"empty",
			"empty",
			"empty",
			"empty",
			"empty",
			"empty",
			"empty",
			"empty",
		};
		*/

		Vector2 scrollPosition = Vector2.zero;
		float titleTopMargin = 20f;
		
		void OnGUI () {
			Vector3 po = Camera.main.WorldToScreenPoint(transform.position);

			Bounds menuTabBounds = GameObject.Find ("MenuTab").transform.renderer.bounds;
			Vector3 menuTabBottomLeft = Camera.main.WorldToScreenPoint(new Vector3(menuTabBounds.min.x, menuTabBounds.min.y, 0));
			Vector3 menuTabUpperRight = Camera.main.WorldToScreenPoint(new Vector3(menuTabBounds.max.x, menuTabBounds.max.y, 0));
			float menuTabHeight = (menuTabUpperRight.y - menuTabBottomLeft.y);

			float listAreaHeight = (float)Screen.height - menuTabHeight - titleTopMargin;

			GUILayout.BeginArea(new Rect((float)Screen.width/2 - po.x,
			                             (float)Screen.height/2 - po.y + titleTopMargin,
			                             (float)Screen.width,
			                             listAreaHeight));

			GUILayout.Label ("LIST", titleStyle);


         GUI.skin.verticalScrollbar.fixedWidth = 20f;
         GUI.skin.verticalScrollbar.normal.background = null;
         GUI.skin.verticalScrollbarThumb = scrollbarThumb;
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true); 

			GUILayout.BeginVertical();
			foreach (string item in Global.storyInfo.chapters)
			{
				GUILayout.Button(item, itemStyle, GUILayout.ExpandWidth(true));
			}			
			GUILayout.EndVertical();

			GUILayout.EndScrollView();
			GUILayout.EndArea();
		}
   }
}